package cn.nio.test;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main3 {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(4,
                6, 3,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(5));
        threadPoolExecutor.execute(() -> System.out.println(Thread.currentThread().getName() + ": 112"));
        Thread.sleep(1000);
        threadPoolExecutor.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ": 112");
            try {
                Thread.sleep(3000);
                System.out.println();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        threadPoolExecutor.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ": 112");
            try {
                Thread.sleep(3000);
                System.out.println(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        threadPoolExecutor.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ": 112");
            try {
                Thread.sleep(3000);
                System.out.println(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        threadPoolExecutor.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ": 112");
            try {
                Thread.sleep(3000);
                System.out.println(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        threadPoolExecutor.execute(() -> {
            System.out.println(Thread.currentThread().getName() + ": 112");
            try {
                Thread.sleep(3000);
                System.out.println(4);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        threadPoolExecutor.shutdown();
    }
}
